import axios from './axios'
import qs from 'qs'
import { apiUrl, appUrl, baseUrl3, eshopUrl} from '@/config/config'

// 读取家长"我的页面"内容
export const parentDirectoryApi = () => {
return new Promise((resolve, reject) => {
  axios({
    url: appUrl + '/bdc/api/app/users/parentMyPage',
    method: 'get'
  }).then(res => {
    resolve(res.data)
  }).catch(err => {
    reject(err)
  })
})
}

// 读取老师"我的页面"内容
export const teacherDirectoryApi = () => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/users/teacherMyPage',
      method: 'get'
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 家长获取我的孩子记录（包括审核中和驳回的）
export const getChildRecordsApi = () => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/student/parentStudentApprovalList',
      method: 'get'
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}


// 获取字典枚举数据 FamilyRelation（亲属关系）  IdCardType（证件类型）
export const getDictionariesApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/dictionaryvalue',
      method: 'get',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 检测用户是否可以添加孩子
export const postTestingAddApi = () => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/student/checkStudentApprovalRole',
      method: 'post'
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 创建孩子审核记录
export const postChildAuditApi = (data) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/student/studentApproval',
      method: 'post',
      data: data
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 修改孩子审核记录
export const updateChildAuditApi = (data) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/student/studentApproval',
      method: 'put',
      data: data
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 删除与孩子的关联
export const deleteChildContactApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/student/studentApproval',
      method: 'delete',
      params
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 根据班级号获取学校班级
export const getClassNumberApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/school/classesQrCode',
      method: 'get',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 修改昵称  老师（teacherName）  家长（parentName）
export const putChangeNicknameApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/users/' + params.id + '/' + params.type,
      method: 'put',
      data: params.data
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 修改头像  老师（teacherHeadImg）  家长（parentHeadImg）
export const putChangeHeadImgApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/users/' + params.id + '/' + params.type,
      method: 'put',
      data: params.data
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 修改密码
export const putChangepwd = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/users/' + params.id + '/password',
      method: 'put',
      data: params.data
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 获取需要审核的班级
export const getTrialClassApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/teacher/' + params + '/gradeClases',
      method: 'get'
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 教师获取班级学生的审核记录
export const getTrialStudentApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/student/studentApprovalList',
      method: 'get',
      params
    }).then(res => {
      resolve(res.data.items)
    }).catch(err => {
      reject(err)
    })
  })
}

// 批量审核家长添加的孩子
export const postBatchTrialApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/student/batchApprovalStudent',
      method: 'post',
      data: params
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 单条审核家长添加的孩子
export const postSingleTrialApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/student/singleApprovalStudent',
      method: 'post',
      data: params
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 获取一卡通列表
export const getOnCardListApi = () => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/student/studentConsumerCardNos',
      method: 'get'
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 学生绑定消费卡
export const getBindingApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/safety/api/device/studentDeviceOneCardManager/studentDeviceBindConsumerCard',
      method: 'post',
      data: params
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 学生解绑消费卡
export const getUnbundlingApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/safety/api/device/studentDeviceOneCardManager/studentDeviceConvenient',
      method: 'delete',
      params
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 学生检测是否绑定消费卡
export const postDetectBindingApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/safety/api/device/studentDeviceOneCardManager/checkBindingCard',
      method: 'post',
      data: params
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}


// 获取家长下学生的设备信息
export const getAllEquipmentListApi = () => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/safety/api/device/studentDevice/parentStudentDeviceInfos',
      method: 'get'
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 给学生绑定 && 修改设备信息
export const postbindingDeviceApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/safety/api/device/studentDevice/bindOrUpdateStudentDevice',
      method: 'post',
      data: params
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 获取已设置的亲情号码
export const getFamilyNumApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/safety/api/device/studentDevice/familyPhonesState/' + params,
      method: 'get'
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 设置亲情号码
export const postFamilyNumApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/safety/api/device/studentDevice/setOrUpdateFamilyPhones',
      method: 'post',
      data: params
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 设置sos亲情号码
export const postFamilyNumSOSApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/safety/api/device/studentDevice/setOrUpdateSOSPhones',
      method: 'post',
      data: params
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 教师主动创建班级
export const postCreateClassApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/school/classByTeacher',
      method: 'post',
      data: params
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 获取用户上级邀请者信息  （加入班级页面，获取默认班级使用）
export const getSuperiorApi = () => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/school/inviteUserInfo',
      method: 'get'
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 获取授课教师年级班级
export const getTeachingApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/teacher/' + params +'/gradeClases',
      method: 'get'
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 获取默认学校学校信息  （获取学段学级用）
export const getDefaultSchoolApi = () => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/school/spreadDefaultSchool',
      method: 'get'
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 根据学校id获取学段学级
export const getLearningSectionApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/school/' + params + '/stages',
      method: 'get'
    }).then(res => {
      resolve(res.data.items)
    }).catch(err => {
      reject(err)
    })
  })
}

// 根据学校码获取学校信息
export const getQRCodeApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/school/schoolQRCode',
      method: 'get',
      params: {
        qrcode: params
      }
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 更新家长审核设置
export const putSetUpApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/student/parentApprovalConfig',
      method: 'put',
      data: params
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 教师加入已有班级
export const postExistenceClassApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/school/joinClassByTeacher',
      method: 'post',
      data: params
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 根据班级码获取   家长   分享二维码
export const getQRcodeUserApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/users/inviteParentQRCode',
      method: 'get',
      params: {
        qrcode: params
      }
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 根据班级码获取  教师   分享二维码
export const getInviteTeachersApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/users/inviteTeacherQRCode',
      method: 'get',
      params: {
        qrcode: params
      }
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 查询教师用户信息
export const getTeacherInfoApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/teacher/' + params,
      method: 'get'
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 家长获取我的订单列表
export const getMyOrderApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: eshopUrl + '/api/logistics/orders',
      method: 'get',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 创建班级  获取默认设置
export const getSetUpApi = () => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/student/parentApprovalConfig',
      method: 'get'
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 更新班级  获取默认设置
export const putSetUpTwoApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/student/parentApprovalConfig',
      method: 'put',
      data: params
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 获取登录用户的教师信息  （教师登录以后，退出直接扫码进入时使用）
export const getTeacherApi = () => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/users/teacher',
      method: 'get',
      ignoreError: true
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 教师创建班级时，获取当前教师年级信息
export const getTeacherGradeApi = () => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/school/establishClassGrades',
      method: 'get',
      params: {
        Sorting: 'orderNum ASC'
      }
    }).then(res => {
      resolve(res.data.items)
    }).catch(err => {
      reject(err)
    })
  })
}

// 获取某个年级的学科
export const getTeacheSubjectApi = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/school/subjects',
      method: 'get',
      params: {
        StageId: params
      }
    }).then(res => {
      resolve(res.data.items)
    }).catch(err => {
      reject(err)
    })
  })
}

// 确认加入一起做公益
export const putPublicWelfareApi = () => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/users/userBenefit',
      method: 'put'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

export const recommendFriendQRCode = () => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/users/recommendFriendQRCode',
      method: 'get'
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

// 获取推荐同事的二维码
export const getColleagueApi = () => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/users/recommendColleagueQRCode',
      method: 'get'
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}
// 获取班级的老师和家长
export const teacherAndParent = (classId) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/school/teacherAndParent/' + classId,
      method: 'get'
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}
// 教师退出班级
export const quitClass = ({classId, teacherId}) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/teacher/'+teacherId+'/exitClasses/' + classId,
      method: 'post'
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}
// 班主任解散班级
export const dissolveClass = ({classId, teacherId}) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/teacher/'+teacherId+'/dissolveClass/' + classId,
      method: 'post'
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}
// 更新教师的教学科目
export const updateSubjectByTeacher = ({id, data}) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/teacher/'+id+'/subjects',
      method: 'put',
      data
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}
// 获取该学校所有的学科
export const getAllSubject = ({id, params}) => {
  return new Promise((resolve, reject) => {
    axios({
      url: appUrl + '/bdc/api/app/school/' + id + '/subjects',
      method: 'get',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

